﻿using Orchard.ContentManagement.MetaData;
using Orchard.Data.Migration;

namespace AwesomeSlider
{
    public class Migration : DataMigrationImpl
    {
        public int Create() 
        {
            //Creating table SliderPartRecord
            SchemaBuilder.CreateTable("SliderPartRecord",
                table => table.ContentPartRecord()
                    .Column<string>("Description", c => c.Unlimited())
                );
            ContentDefinitionManager.AlterTypeDefinition("SliderConfiguration",
            cfg => cfg
            .WithPart("SliderPart")
            .WithPart("CommonPart")
            .WithPart("RoutePart")
            .WithPart("MenuPart")
            );

            return 1;
        }

        public int UpdateFrom1()
        {
            SchemaBuilder.CreateTable("SliderItemPartRecord",
                table => table.ContentPartRecord()
                    .Column<string>("FileName")
                    .Column<string>("FileExtension")
                    .Column<string>("Description", c => c.Unlimited())
                );

            ContentDefinitionManager.AlterTypeDefinition("SliderItem",
            cfg => cfg
                .WithPart("SliderItemPart")
                .WithPart("CommonPart")
                .WithPart("RoutePart")
                .WithPart("PublishLaterPart")
            );

            return 2;
        }
    }
}